import struct,numpy as np

type2code = {'uint8':0x08,'int8':0x09,'int16':0x0B,'int32':0x0C,'float32':0x0D,'float64':0x0E}
def createMatrix(low=0,high=1000,size=[0,3000]):
    return np.random.uniform(low,high,size).astype('>f4')

def writeMatrix2(filename,matrix=createMatrix()):
    with open(filename, 'wb') as f:
        shapes = matrix.shape
        fmt = '>HBB'
        fhead = struct.pack(fmt, 0,type2code[matrix.dtype.name],len(shapes))
        f.write(fhead)
        fmt = '>{}I'.format(len(fhead))
        fhead = struct.pack(fmt,shapes)
        f.write(fhead)
        f.write(fmt)